package Filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(filterName = "loginFilter2")
public class loginFilter2 implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) resp;
        HttpSession session = req.getSession(true);
        Object obj1 = session.getAttribute("userName");
        Object obj2 = session.getAttribute("token");
        String uri = ((HttpServletRequest) request).getRequestURI();
        System.out.println(uri);
//        if( uri.contains("/login.jsp") || obj2 != null ) {
//            chain.doFilter(req, resp);
//            return;
//        }
//
//        if((obj1 ==  null|| ((String) obj1).length() ==0 ) && obj2 == null){
//            res.sendRedirect("https://cas.dgut.edu.cn?appid=javaee&state=STATE");
//            System.out.println((String) obj1);
//            chain.doFilter(req, res);
//        }
        chain.doFilter(req, res);
    }
    @Override
    public void init(FilterConfig config) throws ServletException {
    }

    @Override
    public void destroy() {
    }

}